#!/bin/bash

# 阿里巴巴B2B主题测试脚本

echo "🚀 开始测试阿里巴巴B2B主题..."
echo "📍 测试地址: http://localhost:8090"

# 检查应用状态
echo "📊 检查应用状态..."
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8090)
if [ "$HTTP_CODE" = "200" ]; then
    echo "✅ 应用运行正常 (HTTP $HTTP_CODE)"
else
    echo "❌ 应用状态异常 (HTTP $HTTP_CODE)"
    exit 1
fi

# 检查主题文件
echo "📁 检查主题文件..."
THEME_DIR="/Users/wangqi/Documents/code/privateorder/pan/halo/application/src/main/resources/themes/alibaba-b2b-theme"
if [ -d "$THEME_DIR" ]; then
    echo "✅ 主题目录存在"
    
    # 检查关键文件
    files=(
        "theme.yaml"
        "templates/layout.html"
        "templates/index.html"
        "assets/css/style.css"
        "assets/js/main.js"
        "settings.yaml"
    )
    
    for file in "${files[@]}"; do
        if [ -f "$THEME_DIR/$file" ]; then
            echo "✅ $file 存在"
        else
            echo "❌ $file 不存在"
        fi
    done
else
    echo "❌ 主题目录不存在"
    exit 1
fi

# 检查静态资源
echo "🖼️ 检查静态资源..."
IMAGE_DIR="$THEME_DIR/assets/images"
if [ -d "$IMAGE_DIR" ]; then
    image_count=$(find "$IMAGE_DIR" -name "*.jpg" -o -name "*.png" -o -name "*.gif" | wc -l)
    echo "✅ 图片资源: $image_count 个"
    
    # 列出主要图片
    echo "📋 主要图片文件:"
    find "$IMAGE_DIR" -name "*.jpg" -o -name "*.png" | head -5
else
    echo "❌ 图片目录不存在"
fi

# 检查CSS样式
echo "🎨 检查CSS样式..."
CSS_FILE="$THEME_DIR/assets/css/style.css"
if [ -f "$CSS_FILE" ]; then
    line_count=$(wc -l < "$CSS_FILE")
    echo "✅ CSS样式文件: $line_count 行"
    
    # 检查关键样式
    if grep -q "alibaba" "$CSS_FILE"; then
        echo "✅ 包含阿里巴巴风格样式"
    fi
    
    if grep -q "nav-bar" "$CSS_FILE"; then
        echo "✅ 包含导航栏样式"
    fi
    
    if grep -q "product-categories" "$CSS_FILE"; then
        echo "✅ 包含产品分类样式"
    fi
    
    if grep -q "hero-section" "$CSS_FILE"; then
        echo "✅ 包含轮播图样式"
    fi
else
    echo "❌ CSS样式文件不存在"
fi

# 检查JavaScript功能
echo "⚡ 检查JavaScript功能..."
JS_FILE="$THEME_DIR/assets/js/main.js"
if [ -f "$JS_FILE" ]; then
    line_count=$(wc -l < "$JS_FILE")
    echo "✅ JavaScript文件: $line_count 行"
    
    # 检查关键功能
    if grep -q "swiper" "$JS_FILE"; then
        echo "✅ 包含轮播图功能"
    fi
    
    if grep -q "modal" "$JS_FILE"; then
        echo "✅ 包含模态框功能"
    fi
    
    if grep -q "animations" "$JS_FILE"; then
        echo "✅ 包含动画功能"
    fi
else
    echo "❌ JavaScript文件不存在"
fi

# 检查响应式设计
echo "📱 检查响应式设计..."
if grep -q "@media" "$CSS_FILE"; then
    media_queries=$(grep -c "@media" "$CSS_FILE")
    echo "✅ 响应式设计: $media_queries 个媒体查询"
    
    # 检查关键断点
    if grep -q "768px" "$CSS_FILE"; then
        echo "✅ 包含平板设备适配"
    fi
    
    if grep -q "576px" "$CSS_FILE"; then
        echo "✅ 包含手机设备适配"
    fi
else
    echo "❌ 没有响应式设计"
fi

# 生成测试报告
echo ""
echo "📋 测试报告摘要:"
echo "================================"
echo "🌐 应用地址: http://localhost:8090"
echo "🎨 主题名称: 阿里巴巴B2B企业主题"
echo "📦 主题版本: 1.0.0"
echo "🎯 主要特性:"
echo "   - 阿里巴巴风格的橙色主题"
echo "   - 响应式设计，支持移动端"
echo "   - 产品分类展示"
echo "   - 轮播图功能"
echo "   - 多语言支持"
echo "   - 社交媒体集成"
echo "   - SEO优化"
echo "================================"

echo ""
echo "🎉 测试完成！"
echo "📝 请在浏览器中访问 http://localhost:8090 查看效果"
echo "🔧 管理后台: http://localhost:8090/console"